﻿using Ewell.BizComponent.Service.Model;
using Ewell.Interface.Common.Model.GateWay;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ewell.BizComponent.Service.Server
{
    /// <summary>
    /// 接口代理
    /// </summary>
    [Obsolete]
    public class InterfaceProxyServer
    {
        /// <summary>
        /// 使用独立进程调用接口代理
        /// </summary>
        /// <returns></returns>
        public static GateWayResult<T> InvokeWithProce<T>(PipeProxyRequest param)
        {
            Guid pipeName = Guid.NewGuid();
            param.pipeName= pipeName.ToString();
            GateWayResult<T> result = new GateWayResult<T>()
            {
                success = false,
                message = "错误的通讯!",
            };
            // 创建一个进程启动信息
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                FileName = "Ewell.Interface.Proxy.exe",
                Arguments = JsonConvert.SerializeObject(param),
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            using (Process process = new Process())
            {
                //创建监听服务
                //独立进程调用
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
                //等待结果
                

                //result = JsonConvert.DeserializeObject<GateWayResult<T>>(resultStr);
            }
            return result;
        }
    }
}
